<?php
namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Activity extends Model
{
    use SoftDeletes;
    
    protected $table = 'activity';
    protected $fillable = [
        'title', 'status',  'sponsor_id', 'prize_ids', 'start_at', 'end_at', 'imgs_ids', 'prize_desc'
    ];

    // 定义多对多关系关联用户信息
    public function members()
    {
        return $this->belongsToMany(Member::class, 'record', 'activity_id', 'member_id');
    }

    //定义赞助商的关联关系
    public function sponsors()
    {
        return $this->belongsTo(Sponsors::class, 'sponsor_id');
    }

    // 关联中奖者信息
    public function winner()
    {
        return $this->hasManyThrough(Member::class,Record::class,'activity_id','id','id','member_id');
    }
}
